#include "Utils.h"
#include <assert.h>
#include <fstream>

void PrintError(const TCHAR *prefix, DWORD errorCode) {
  assert(false);
  TCHAR errorMsg[256] = {0};
  FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, errorCode,
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errorMsg,
                sizeof(errorMsg) / sizeof(TCHAR), NULL);
  _tprintf(_T("%s failed with error code %d: %s\n"), prefix, errorCode,
           errorMsg);
  std::wofstream file(L"F:\\src\\HookF3\\error.log", std::ios::app);
  if (file.is_open()) {
    file << prefix << L" failed with error code " << errorCode << L": "
         << errorMsg << std::endl;
  }
}

void PrintLog(const TCHAR *msg, const TCHAR *filename, int lineno) {
  _tprintf(_T("%s:%d\t\t%s\n"), filename, lineno, msg);
  std::wofstream file(L"F:\\src\\HookF3\\error.log", std::ios::app);
  if (file.is_open()) {
    file << filename << L" :" << lineno << L"\t\t" << msg << std::endl;
  }
}
